package org.example;

import java.util.Random;

/**
 * Hello world!
 */
public class BaseClass {
    //父类要有无参构造器
    //有抽象方法的类是抽象类
    //抽象类不能实例化
    //抽象方法子类必须实现
    int hh;
    public BaseClass(int hh) {
        this.hh = hh;
    }
    public BaseClass() {}
    public void shout() {
        System.out.println("哈哈哈");
    }
    public static void AnimalShout(BaseClass animal){
        animal.shout(); //多态
    }
    public static void main(String[] args) {
        System.out.println(new Random().nextInt(20));
        BaseClass a=new BaseClass(1);
        BaseClass b=new Cat();
        BaseClass c=new Mouse();
        BaseClass d=new Dog();
        AnimalShout(a);
        AnimalShout(b);
        AnimalShout(c);
        Cat cat=(Cat)b;
        cat.CatSelf();
//        Dog dog=(Dog)c; //报错  转换之前用instanceof 判断类型
//        System.out.println(c.hh);
//        System.out.println(a==b);
//        System.out.println(a.equals(b)); //重写
//        h(a.a,b.a);
//        System.out.println(a.a);
//        System.out.println(b.a);
//        int c=20;
//        h(c,c);
//        System.out.println(PI);
    }
    public static void h(int a, int b){
        a++;
        b++;
    }
}
class Dog extends BaseClass{
    @Override
    public void shout() {
        System.out.println("狗");
    }
    public void DogSelf(){
        System.out.println("我是Dog");
    }
}
class Cat extends BaseClass{
    @Override
    public void shout() {
        System.out.println("猫");
    }
    public void CatSelf(){
        System.out.println("我是Cat");
    }
}
class Mouse extends BaseClass{}
//接口也可以在实例中声明